<?php
include ("../include/config.php");

require($config['basedir']."/include/authenticate.php");
require($config['basedir']."/admin/classes/category.class.php");
$post = $_REQUEST;
$obj_cat = new Category();

$_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';

switch($_action) {

	case 'add':
   	$post = $_POST;
	
		if (isset($_POST['submit']))
		{   
			$obj_cat->addCategory($post);
		}
		stemplate::assign("post", $post);		
		stemplate::display("admin/category/save.tpl");
		
	break;
	
	case 'edit':

		if (isset($post['submit']))
		{
			$obj_cat->updateCategory($post);
		}
		else
		{
			$post = $obj_cat->getCategoryById($post['category_id']);	
		}	

		stemplate::assign("post", $post);
		//stemplate::assign("category_id", $post['category_id']);
		stemplate::display("admin/category/save.tpl");
	break;
	
	
	case 'delete':
	    $obj_cat->deleteCategory($post['category_id']);
		 
		 global $pager;
		stemplate::assign('categories', $obj_cat->getCategories($post));
		stemplate::assign("post", $post);
		stemplate::assign("total_records", $pager->items_total);
  		stemplate::assign("pagination_start", $pager->low);
  		stemplate::assign("pagination",$pager->display_pages());
		stemplate::assign("page_limit_select", $pager->display_page_limits());
		stemplate::display("admin/category/list.tpl");
		 
	break;	
	
	
	case 'view':
	default:
		
		$post = $_REQUEST;
		
		if($_REQUEST['added'] == 1)	{
			global $msgOk;
			$msgOk = 'Category added successfully.';
		}elseif($_REQUEST['updated'] == 1){
			global $msgOk;
			$msgOk = 'Category updated successfully.';
		}elseif($_REQUEST['deleted'] == 1){
			global $msgOk;
			$msgOk = 'Category deleted successfully.';
		}
		
		global $pager;
		stemplate::assign('categories', $obj_cat->getCategories($post));
		stemplate::assign("post", $post);
		stemplate::assign("total_records", $pager->items_total);
  		stemplate::assign("pagination_start", $pager->low);
  		stemplate::assign("pagination",$pager->display_pages());
		stemplate::assign("page_limit_select", $pager->display_page_limits());
		stemplate::display("admin/category/list.tpl");
		
    break; 

}




?>